package com.csf.project.controller;

import com.csf.project.entity.TlbbAreaDatas;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.csf.project.constatns.CommonConstants;
import com.csf.project.entity.User;
import com.csf.project.msg.ObjectRestResponse;
import com.csf.project.service.AuthService;

@RequestMapping("/auth")
@RestController
@Api(tags = "登录")
public class AuthController {

    @Autowired
    AuthService authService;
    @ApiOperation(value ="用户登录获取Token",httpMethod = "POST")
    @RequestMapping(value = "/login", method = RequestMethod.POST)
    public  ObjectRestResponse<Object> login(@RequestBody User user) throws Exception {
    	ObjectRestResponse<Object> result = new ObjectRestResponse<Object>();
        User resultUser = authService.login(user.getUsername(), user.getPassword());
        if (resultUser != null) {
        	result.setRel(true);
        	result.setState(0);
        	result.setData(resultUser);
            return result;
        }else {
        	result.setRel(false);
        	result.setStatus(500);
        	result.setState(CommonConstants.EX_USER_INVALID_CODE);
            return result;
        }
    }


}
